package com.ruoyi.post.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.post.domain.PostContent;
import com.ruoyi.post.service.IPostContentServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.post.mapper.PostMapper;
import com.ruoyi.post.domain.Post;
import com.ruoyi.post.service.IPostService;

/**
 * 发帖管理Service业务层处理
 * 
 * @author gu
 * @date 2025-05-18
 */
@Service
public class PostServiceImpl implements IPostService
{
    @Autowired
    private PostMapper postMapper;
    @Autowired
    private IPostContentServise postContentServise;
    /**
     * 查询发帖管理
     * 
     * @param id 发帖管理主键
     * @return 发帖管理
     */
    @Override
    public Post selectPostById(Long id)
    {
        Post post = postMapper.selectPostById(id);
        PostContent content = postContentServise.getById(id.toString());
        post.setContent(content.getContent());

        return post;
    }

    /**
     * 查询发帖管理列表
     * 
     * @param post 发帖管理
     * @return 发帖管理
     */
    @Override
    public List<Post> selectPostList(Post post)
    {
        List<Post> posts = postMapper.selectPostList(post);
        return posts;
    }

    /**
     * 新增发帖管理
     * 
     * @param post 发帖管理
     * @return 结果
     */
    @Override
    public int insertPost(Post post)
    {
        post.setCreateTime(DateUtils.getNowDate());
        int i = postMapper.insertPost(post);
        if (i>0){
            Long id = post.getId();
            String content = post.getContent();
            PostContent postContent = new PostContent();
            postContent.setId(id.toString());
            postContent.setContent(content);
            postContentServise.insert(postContent);
        }


        return i;
    }

    /**
     * 修改发帖管理
     * 
     * @param post 发帖管理
     * @return 结果
     */
    @Override
    public int updatePost(Post post)
    {
        return postMapper.updatePost(post);
    }

    /**
     * 批量删除发帖管理
     * 
     * @param ids 需要删除的发帖管理主键
     * @return 结果
     */
    @Override
    public int deletePostByIds(Long[] ids)
    {
         ;
        return postMapper.deletePostByIds(ids);
    }

    /**
     * 删除发帖管理信息
     * 
     * @param id 发帖管理主键
     * @return 结果
     */
    @Override
    public int deletePostById(Long id)
    {
        postContentServise.delete(id.toString());
        int i = postMapper.deletePostById(id);
        return i;
    }
}
